package com.ljx.thread.thread01;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/10/31 15:10
 * @Version 1.0
 */
public class GirlThread implements Runnable{
	private Card card;
	public GirlThread(Card card){
		this.card=card;
	}

	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			synchronized (card) {
				if (card.getBalance() >= 1000) {
					card.setBalance(card.getBalance() - 1000);
					System.out.println(Thread.currentThread().getName() + "向银行取了1000 余额为" + card.getBalance());
				} else {
					i--;
				}
			}
		}
	}
}
